package com.base.service.impl;

import com.base.mapper.voipmapper.CollectCommoditiesMapper;
import com.base.po.collect.CollectCommodities;
import com.base.service.CollectCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CollectCommodityServiceImpl implements CollectCommodityService {

    @Autowired
    private CollectCommoditiesMapper collectCommoditiesMapper;

    /**
     * 添加收藏
     * @param collectCommodities
     * @return
     */
    @Override
    public int insertCollectCommodity(CollectCommodities collectCommodities) {
        return collectCommoditiesMapper.insert(collectCommodities);
    }

    /**
     * 获取用户收藏列表
     * @param uId  用户ID
     * @param pId 代理商ID
     * @param start  起始页
     * @param num   查询条数
     * @return
     */
    @Override
    public List<CollectCommodities> findCollectCommodityByUidAndPid(String uId, String pId, Integer start, Integer num) {
        return collectCommoditiesMapper.findCollectCommodityByUidAndPid(uId,pId,start,num);
    }

    /**
     * 删除收藏记录
     * @param ccId
     * @return
     */
    @Override
    @Transactional
    public boolean deleteCollectCommodity(String ccId) {
        return collectCommoditiesMapper.deleteByCcid(ccId);
    }

    /**
     * 更新收藏商品日期
     * @param collectCommodities
     * @return
     */
    @Override
    public boolean updateCollectCommodityDate(CollectCommodities collectCommodities) {
        return collectCommoditiesMapper.updateCollectCommodityDate(collectCommodities);
    }

    @Override
    public boolean hasCommodityBy(String uId, String comId, String parentId) {
        return collectCommoditiesMapper.hasCommodityBy(uId, comId,parentId).size() > 0;
    }

    /**
     * 取消收藏
     * @param collectCommodities
     * @return
     */
    @Override
    public boolean cancelCollect(CollectCommodities collectCommodities) {
        return collectCommoditiesMapper.cancelCollect(collectCommodities);
    }
}
